package com.zzs.server.dao.mysql;

import com.zzs.common.core.entity.mysql.ProblemDO;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author zzs
 * @date 2025/03/17
 */
@Mapper
public interface ProblemMapper {
    @Insert("insert into problem (id, title, content, difficulty, status, create_time, update_time) VALUES (#{id}, #{title}, #{content}, #{difficulty}, #{status}, #{createTime}, #{updateTime})")
    int save(ProblemDO problemDO);

    @Update("update problem set title = #{title}, content = #{content}, difficulty = #{difficulty}, update_time = #{updateTime} where id = #{id} and status = 0")
    int update(ProblemDO problemDO);

    @Select("select exists(select 1 from problem where id = #{id} and status = 1)")
    boolean isPublish(@Param("id") long id);

    @Select("select id, title, content, difficulty from problem where id = #{id}")
    ProblemDO get(@Param("id") long id);

    @Delete("delete from problem where id = #{id}")
    int remove(@Param("id") long id);

    @Select("select exists(select 1 from problem where id = #{id})")
    boolean exists(@Param("id") long id);

    List<ProblemDO> listProblems(@Param("difficulty") Integer difficulty, @Param("keyword") String keyword);

    @Update("update problem set status = #{status} where id = #{id}")
    int setStatus(@Param("id") long id, @Param("status") int status);
}
